<template>
  <div class="login-wrap">
    <el-form class="login-form" label-position="top" label-width="80px" :model="formData">
      <h2>用户登录</h2>
      <el-form-item label="用户名">
        <el-input v-model="formData.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="formData.password" show-password></el-input>
      </el-form-item>
      <el-button class="login-btn" type="primary" @click="login">登录</el-button>
    </el-form>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        formData: {
          username: '',
          password: ''
        }
      }
    },
    methods: {
      async login(){
        const res = await this.$http.post('/login', this.formData)
        if (res.data.code === 200) {
          this.$message.success('登录成功')
          this.$router.push({path: '/'})
        }
      }
    }
  }
</script>

<style>
  .login-wrap {
    height: 100%;
    background-color: #324152;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .login-wrap .login-form {
    background-color: #ffffff;
    width: 400px;
    padding: 20px;
    border-radius: 5px;
  }

  .login-btn {
    width: 100%;
  }

</style>
